package alf.mapping.view.touch;

import alf.mapping.dto.maps.NavigationLink;
import alf.mapping.view.Env;
import alf.mapping.view.visuals.EditorEngine;
import alf.mapping.view.visuals.Sprite;
import android.graphics.Point;
import android.graphics.Rect;
import android.view.MotionEvent;

public class SelectingTouchReactor extends AbstractTouchReactor {
	
	private Sprite oldSel;
	
	@Override
	protected boolean onTouch(MotionEvent event, Point punto, Rect puntogordo) {
		switch (event.getActionMasked()) {
			case MotionEvent.ACTION_DOWN:
				oldSel = spriteAtPos(puntogordo);
				if (oldSel == null) {
					return false;// no recibir mas
				} else {
					//selecting
				}
				break;
			case MotionEvent.ACTION_UP:
				Sprite sel = spriteAtPos(puntogordo);
				if (sel != null && sel.equals(oldSel)) {
					// selected.
					for (Sprite source : editor.getSelected()) {
						NavigationLink nav = new NavigationLink(editor.getCurrentRoom(), sel.getItem());
						editor.createLink(source, nav);
					}
					//	Env.toast(getContext(),"Link created " + sel.getItem().getName());
					editor.setMode(EditorEngine.Mode.EDIT);
				} else {
					Env.toast(ctx, "Select link destination");
				}
				oldSel = null;
				break;
		}
		return true;
	}
}
